package com.jiangjiang.eshop.auth.facade;

import com.jiangjiang.eshop.auth.convert.AccountRoleRelationshipConvert;
import com.jiangjiang.eshop.auth.dto.AccountRoleRelationshipDTO;
import com.jiangjiang.eshop.auth.service.AccountRoleRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName AccountRoleRelationshipFacade
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/7 5:39
 * @Version 1.0
 **/
@Component
public class AccountRoleRelationshipFacade {
    @Autowired
    private AccountRoleRelationshipService accountRoleRelationshipService;
    @Autowired
    private AccountRoleRelationshipConvert accountRoleRelationshipConvert;

    /**
     * 根据用户账户id查询账户与角色关联关系
     * @param accountId 账户id
     * @return 查询结果
     */
    public List<AccountRoleRelationshipDTO> queryRoleRelationsByAccountId(Long accountId) {
        return accountRoleRelationshipConvert.convertEntity2DTO(
                accountRoleRelationshipService.queryRoleRelationsByAccountId(accountId)
        );
    }

    /**
     * 角色和账号的关联关系保存
     * @param roleRelations
     */
    public void saveRelationShip(List<AccountRoleRelationshipDTO> roleRelations) {
        accountRoleRelationshipService.saveBatch(accountRoleRelationshipConvert.convertDTO2Entity(roleRelations));
    }

    /**
     * 角色和账号的关联关系更新
     * @param roleRelations
     */
    public void relationShipUpdate(List<AccountRoleRelationshipDTO> roleRelations) {
        accountRoleRelationshipService.updateBatchById(accountRoleRelationshipConvert.convertDTO2Entity(roleRelations));
    }
}
